package com.catena.core.chain;

import com.catena.core.CatenaOperationNodeAbstract;
import com.catena.core.NodeReuseException;

/**
 * Created by hx-pc on 16-2-25.
 */
public abstract class CatenaOperationNodeAppender extends CatenaOperationNodeAbstract implements CatebaOperationRun {

    private CatenaOperationNodeAppender node;

    protected CatenaOperationNodeAppender getNextNode() {
        return this.node;
    }

    /**
     * 追加方法append
     * 自动加载到最后一个节点的末尾
     *
     * @param node
     */
    public void append(CatenaOperationNodeAppender node) {
        if (this.node == null) {
            this.node = node;
        } else {
            assert node != null;
            if (node.equals(this)) {
                throw new NodeReuseException();
            }
            this.node.append(node);
        }
    }
}
